import { Controller, Get, Post, Body, Patch, Param, Delete,Req, Query, Res } from '@nestjs/common';
import { DictTypeService } from './dict-type.service';
import { CreateDictTypeDto } from './dto/create-dict-type.dto';
import { UpdateDictTypeDto } from './dto/update-dict-type.dto';
import { QueryDictTypeDto } from './dto/query-dict-type.dto';
import { ApiTags,ApiOperation,ApiBearerAuth } from '@nestjs/swagger';
import { Request,Response } from 'express';
import { DeleteDictTypeDto } from './dto/delete-dict-type.dto';
import { StatusChangeDto } from 'src/common/baseDto/status-change.dto';
import { RequirePermission } from 'src/decorator/reuqire-permission';

@ApiTags('字典类型')
@ApiBearerAuth()
@Controller('dict-type')
export class DictTypeController {
  constructor(private readonly dictTypeService: DictTypeService) {}

  @Post('add')
  @ApiOperation({summary:'创建字典类型'})
  @RequirePermission("system:dict:add")
  create(@Body() createDictTypeDto: CreateDictTypeDto,@Req() req:Request) {
    return this.dictTypeService.create(createDictTypeDto,req);
  }

  @Get()
  @ApiOperation({summary:'获取字典类型列表'})
  @RequirePermission("system:dict:list")
  findAll(@Query() query:QueryDictTypeDto) {
    return this.dictTypeService.findAll(query);
  }

  @Get(':id')
  @ApiOperation({summary:'获取字典类型详情'})
  findOne(@Param('id') id: string) {
    return this.dictTypeService.findOne(+id);
  }

  @Patch(':id')
  @ApiOperation({summary:'更新字典类型'})
  @RequirePermission("system:dict:edit")
  update(@Param('id') id: string, @Body() updateDictTypeDto: UpdateDictTypeDto,@Req() req:Request) {
    return this.dictTypeService.update(+id, updateDictTypeDto,req);
  }

  @Post('statusChange')
  @ApiOperation({ summary: '更新字典类型状态' })
  @RequirePermission("system:dict:edit")
  statusChange(@Body() statusChangeDto: StatusChangeDto,@Req() req:Request) {
    return this.dictTypeService.statusChange(statusChangeDto,req);
  }

  @Post('delete')
  @ApiOperation({summary:'删除字典类型'})
  @RequirePermission("system:dict:remove")
  remove(@Body() deleteDictTypeDto: DeleteDictTypeDto) {
    return this.dictTypeService.remove(deleteDictTypeDto);
  }

  @Post('excel')
  @ApiOperation({ summary: '导出字典类型' })
  @RequirePermission("system:dict:export")
  exportToExcel(@Res() res: Response) {
    return this.dictTypeService.exportToExcel(res);
  }

  @Post('all')
  @ApiOperation({ summary: '获取所有字典类型' })
  @RequirePermission("system:dict:getDcit")
  getDictType() {
    return this.dictTypeService.getDictType();
  }
}
